package com.sgb.kjwl.view.ui.adapter.home;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.LeaseHousesEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.List;

/**
 * 房产列表itme
 */
public class LeaseHouseAdapter extends BaseRecycleAdapter<LeaseHousesEntity> {

    private TextView price_view;
    private TextView tv_area;
    private TextView tv_time;
    private TextView tvIsSelf;
    private double rentalPriceInt;

    public LeaseHouseAdapter(Context context, List<LeaseHousesEntity> datas) {
        super(context, R.layout.item_lease_house, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final LeaseHousesEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        price_view = holder.itemView.findViewById(R.id.price_view);
        tv_area = holder.itemView.findViewById(R.id.tv_area);
        tv_time = holder.itemView.findViewById(R.id.tv_time);
        tvIsSelf = holder.getItem().findViewById(R.id.tv_isSelf);
        tvIsSelf.setVisibility("1".equals(entity.getIsSelf()) ? View.VISIBLE : View.INVISIBLE);
        String rentalPrice = entity.getRentalPrice();
        try {
            rentalPriceInt = Double.valueOf(rentalPrice);
            if (rentalPriceInt <= 0) {
                price_view.setText("面议");
            } else {
                price_view.setText(entity.getRentalPrice() + entity.getRentalSelectPrice());
            }
        } catch (Exception e) {
            price_view.setText("面议");
        }

        tv_area.setText(entity.getCityName() + " " + entity.getAreaName());
        try {
            tv_time.setText(DateUtils.stampToDay(entity.getUpdateTime()));
        } catch (Exception e) {

        }
    }

}
